package com.metagurukul.metaspace.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Ritesh
 * this class is for get connection and close connection
 *
 */
public class DatabaseDAO  {
	protected static Connection con = null;
	protected static ResultSet rs = null;
	protected static PreparedStatement ps = null;
	
	public DatabaseDAO(){
		
	}
/*	public static ResultSet selectRecord(String tableName , String[] fields){
		StringBuilder strbuilder = new StringBuilder();
		String query = null;
		if(tableName == null){
			return null;
		}
		if(fields == null){
			query = "Select * from " + tableName;
		}
		else{
			strbuilder.append("select * from " + tableName + " where ");
			for(int i = 0; i < fields.length ; i++){
				strbuilder.append(fields[i] + " = " + fields[i] + " ");
			}
			query = strbuilder.toString();
		}
		return rs;
		
	}
*/
	
	/**to get a connection
	 * @throws SQLException
	 */
	public static void getConnection() throws SQLException{
		con =  ConnectionDAO.getConnection();
	}
	
	/**to close a connection
	 * @throws SQLException
	 */
	public static void closeConnection() throws SQLException{
		try {
			ConnectionDAO.closeConnection();
			if (con != null) { 
				con.close();
			}
			if (ps != null) {
				ps.close();
			}
			if (rs != null) {
				rs.close();
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			throw new SQLException("Close Connection Error"  + e);
		}
	}

}
